﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

using MaxStudio.Concrete.DBUtility;

namespace MaxStudio.Concrete.Server.Dao
{
    public partial class ConcreteDaoDataContext : System.Data.Linq.DataContext
    {
        #region NeedPayDao

        public List<tb_NeedPay> GetAllNeedPay()
        {

            var query = (from obj in this.tb_NeedPays
                         where obj.IsDelete == 0
                         select obj).ToList();
             
            return query;

        }

        public tb_NeedPay GetNeedPayById(int id)
        {
            return this.tb_NeedPays.SingleOrDefault(tb_NeedPays => tb_NeedPays.Id == id);
        }

        public void CreateNeedPay(tb_NeedPay entity)
        {
            entity.CreateDate = DateTime.Now;
            entity.CreateBy = 1;
            entity.ModifyDate = DateTime.Now;
            entity.ModifyBy = 1;
            tb_NeedPays.InsertOnSubmit(entity);
            this.SubmitChanges();

        }

        public void ModifyNeedPay(tb_NeedPay entity)
        {
            tb_NeedPay instance = this.tb_NeedPays.SingleOrDefault(p => p.Id == entity.Id);
            instance.Amount = entity.Amount;
             
            instance.Description = entity.Description; 
            instance.Id = entity.Id;
            instance.IsDelete = entity.IsDelete;
            instance.VenderId = entity.VenderId;
            instance.Status = entity.Status;
            instance.Tracking = entity.Tracking;

            instance.IsDelete = entity.IsDelete;
            instance.ModifyBy = 1; //Need to get current user
            instance.ModifyDate = DateTime.Now;

            this.SubmitChanges();
        }
        public void DeleteNeedPay(tb_NeedPay entity)
        {
            tb_NeedPay deleteEntity = tb_NeedPays.SingleOrDefault(p => p.Id == entity.Id);
            tb_NeedPays.DeleteOnSubmit(deleteEntity);

            this.SubmitChanges();
        }

        #endregion

    }

}
